package v1

import (
	"github.com/gin-gonic/gin"
	"maya-service/bll"
	"maya-service/model"
	"maya-service/server/web/middleware"
	"maya-service/utils"
)

var AiQuestionConsultStatics = &aiQuestionConsultStatics{}

func init() {
	RegisterRouter(AiQuestionConsultStatics)
}

type aiQuestionConsultStatics struct{}

// Init
func (a *aiQuestionConsultStatics) Init(r *gin.RouterGroup) {
	g := r.Group("/aiQuestionConsultStatics", middleware.Auth())
	{
		g.POST("/create", a.create)
		g.POST("/update", a.update)
		g.POST("/list", a.list)
		g.POST("/delete", a.delete)
		g.POST("/detail", a.find)
	}
}

// create
func (a *aiQuestionConsultStatics) create(c *gin.Context) {
	var (
		in  = &model.AiQuestionConsultStaticsCreateRequest{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		c.Error(err)
		return
	}

	if err = bll.AiQuestionConsultStatics.Create(c.Request.Context(), in); err != nil {
		c.Error(err)
		return
	}
	utils.ResponseOk(c, nil)
}

// update
func (a *aiQuestionConsultStatics) update(c *gin.Context) {
	var (
		in  = &model.AiQuestionConsultStaticsUpdateRequest{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		c.Error(err)
		return
	}

	if err = bll.AiQuestionConsultStatics.Update(c.Request.Context(), in); err != nil {
		c.Error(err)
		return
	}
	utils.ResponseOk(c, nil)
}

// list
func (a *aiQuestionConsultStatics) list(c *gin.Context) {
	var (
		in  = &model.AiQuestionConsultStaticsListRequest{}
		out = &model.AiQuestionConsultStaticsListResponse{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		c.Error(err)
		return
	}

	if out, err = bll.AiQuestionConsultStatics.List(c.Request.Context(), in); err != nil {
		c.Error(err)
		return
	}
	utils.ResponseOk(c, out)
}

// list
func (a *aiQuestionConsultStatics) find(c *gin.Context) {
	var (
		in  = &model.AiQuestionConsultStaticsInfoRequest{}
		out = &model.AiQuestionConsultStaticsInfo{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		c.Error(err)
		return
	}

	if out, err = bll.AiQuestionConsultStatics.Find(c.Request.Context(), in); err != nil {
		c.Error(err)
		return
	}
	utils.ResponseOk(c, out)
}

// delete
func (a *aiQuestionConsultStatics) delete(c *gin.Context) {
	var (
		in  = &model.AiQuestionConsultStaticsDeleteRequest{}
		err error
	)

	if err = c.ShouldBindJSON(in); err != nil {
		c.Error(err)
		return
	}

	if err = bll.AiQuestionConsultStatics.Delete(c.Request.Context(), in); err != nil {
		c.Error(err)
		return
	}
	utils.ResponseOk(c, nil)
}
